import {
  ajax,
} from '../../utils/http-request.js';


/**
 * 查询已添加配件
 * @param param
 * @param orderType
 * @returns {Promise<*>}
 */
export const getDeviceFitting = (param, orderType) => {
  const urlObj = {
    repair: `om/repairworkorder/listRepairWorkorderPartsByWorkId`,
    stand: `om/maintenanceworkorder/listMaintenanceWorkorderPartsByWorkId`,
  };
  const url = urlObj[ orderType ];
  return ajax(url, param, {
    method: 'get',
  });
};

/**
 * 查询仓库
 * @param param
 * @returns {Promise<*>}
 */
export const getStoreDataList = (param) => {
  const url = `om/warehouse/list`;
  return ajax(url, param, {
    method: 'get',
  });
};

/**
 * 查询配件
 * @param param
 * @returns {Promise<*>}
 */
export const getFittingDataList = (param) => {
  const url = `om/partsinventory/listPartsByWcode`;
  return ajax(url, param, {
    method: 'get',
  });
};

/**
 * 添加配件
 * @param param
 * @param orderType
 * @returns {Promise<*>}
 */
export const addFitting = (param, orderType) => {
  const urlObj = {
    repair: `om/repairworkorder/addRepairWorkorderParts`,
    stand: `om/maintenanceworkorder/addMaintenanceWorkorderParts`,
  };
  const url = urlObj[ orderType ];
  return ajax(url, param);
};

/**
 * 删除配件
 * @param param
 * @param orderType
 * @returns {Promise<*>}
 */
export const delFitting = (param, orderType) => {
  const urlObj = {
    repair: `om/repairworkorder/deleteRepairWorkorderParts`,
    stand: `om/maintenanceworkorder/deleteMaintenanceWorkorderParts`,
  };
  const url = urlObj[ orderType ];
  return ajax(url, param, {
    method: 'get',
  });
};

export default {
  getDeviceFitting,
  getStoreDataList,
  getFittingDataList,
  addFitting,
  delFitting,
};
